import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path:'/',
      redirect:'/login',
    },
    {
      path:'/login',
      name:'Login',
      component: () => import('../views/Login.vue')
    },
    {
      path:'/register',
      name:'Register',
      component: () => import('../views/register.vue')
    },
    {
      path:'/main',
      name:'MainIndex',
      component: () => import('../views/MainIndex.vue')
    },
    {
      path:'/wjmm',
      name:'Wjmm',
      component: () => import('../views/wjmm.vue')
    },
    {
      path:'/xgmm',
      name:'Xgmm',
      component: () => import('../views/xgmm.vue')
    },
    {
      path:'/publish',
      name:'PublishAnnouncement',
      component: () => import('../views/PublishAnnouncement.vue')
    },
    {
      path:'/ksgl',
      name:'Ksgl',
      component: () => import('../views/ksgl.vue')
    },
    {
      path:'/fbks',
      name:'Fbks',
      component: () => import('../views/fbks.vue')
    },
    {
      path:'/pgsj',
      name:'Pgsj',
      component: () => import('../views/pgsj.vue')
    },
    {
      path:'/yjjm',
      name:'Yjjm',
      component: () => import('../views/yjjm.vue')
    },
    {
      path:'/tkgl',
      name:'Tkgl',
      component: () => import('../views/tkgl.vue')
    },
    {
      path:'/tkglYW',
      name:'TkglYW',
      component: () => import('../views/tkglYW.vue')
    },
    {
      path:'/tkglSX',
      name:'TkglSX',
      component: () => import('../views/tkglSX.vue')
    },
    {
      path:'/tkglYY',
      name:'TkglYY',
      component: () => import('../views/tkglYY.vue')
    },
    {
      path:'/tjtmYW',
      name:'TjtmYW',
      component: () => import('../views/tjtmYW.vue')
    },
    {
      path:'/tjtmSX',
      name:'TjtmSX',
      component: () => import('../views/tjtmSX.vue')
    },
    {
      path:'/tjtmYY',
      name:'TjtmYY',
      component: () => import('../views/tjtmYY.vue')
    },
    {
      path:'/grzx',
      name:'Grzx',
      component: () => import('../views/grzx.vue')
    },
    {
      path:'/home',
      name:'Home',
      component: () => import('../views/student/home.vue')
      
    },
    {
      path:'/zxlx',
      name:'Zxlx',
      component: () => import('../views/student/zxlx.vue')
    },
    {
      path:'/zxlxYW',
      name:'ZxlxYW',
      component: () => import('../views/student/zxlxYW.vue')
    },
    {
      path:'/zxlxSX',
      name:'ZxlxSX',
      component: () => import('../views/student/zxlxSX.vue')
    },
    {
      path:'/zxlxYY',
      name:'ZxlxYY',
      component: () => import('../views/student/zxlxYY.vue')
    },
    {
      path: '/lxym',
      name: 'Lxym',
      component: () => import('../views/student/lxym.vue'),
      props: (route) => ({
        questions: route.state?.questions || [],
        practiceMode: route.state?.practiceMode || 'sequential'
      })
    },
    {
      path:'/lxjl',
      name:'Lxjl',
      component: () => import('../views/student/lxjl.vue')
    },
    {
      path:'/zxks',
      name:'Zxks',
      component: () => import('../views/student/zxks.vue')
    },
  ]
})


router.beforeEach((to, from, next) => {
  const isAuthRequired = to.matched.some(record => record.meta.requiresAuth)
  
  if (isAuthRequired && !isAuthenticated()) {
    next({
      path: '/login',
      query: { redirect: to.fullPath }
    })
  } else {
    next()
  }
})
export default router
